package com.sgb.kjwl.view.ui.adapter.base;

import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.InsetDrawable;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.ColorInt;
import androidx.annotation.IntDef;
import androidx.databinding.BindingAdapter;

import com.bumptech.glide.Glide;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Field;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.PARAMETER;

/**
 * Describe:    用于抽离 dataBinding 内设置属性的 java 逻辑代码
 * Author:  yangLei
 * Date:    2021/12/13
 */
public class CommonBindingAdapter {

    private static final int INVALID = 0;
    private static final int[] TMP_PADDING = new int[4];

    @BindingAdapter(value = {"view_text"})
    public static void setViewText(View view, String text) {
        if (view != null) {
            if (view instanceof TextView) {
                TextView textView = (TextView) view;
                textView.setText(text);
            } else if (view instanceof EditText) {
                EditText editText = (EditText) view;
                editText.setText(text);
            } else if (view instanceof Button) {
                Button button = (Button) view;
                button.setText(text);
            }
        }
    }

    @BindingAdapter(value = {"image_url"}, requireAll = false)
    public static void loadingImage(ImageView imageView, String url) {
        if (!TextUtils.isEmpty(url)) {
            Glide.with(imageView.getContext())
                    .load(url)
                    .into(imageView);
        }
    }
}
